package com.le.tester.leetcode;

import java.util.Arrays;

/**
 * createTime：2021/8/10 16:27
 * description：买卖股票的最佳时机
 */
public class Profit {
    public int maxProfit(int[] prices) {
        int minPrice = Integer.MAX_VALUE;
        int maxProfit = 0;
        for (int price : prices) {
            if (price < minPrice) {
                minPrice = price;
            } else if (price - minPrice > maxProfit) {
                maxProfit = price - minPrice;
            }

        }
        return maxProfit;
    }

    public static void main(String[] args) {
        System.out.println(new Profit().maxProfit(new int[]{7, 1, 5, 3, 6, 4}));
    }
}
